package socket02;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class SocketTCP02Client
{
    public static void main(String[] args) throws IOException
    {
        //连接本机的端口9999
        Socket socket = new Socket(InetAddress.getLocalHost(),9999);
        System.out.println("客户端socket"+socket.getClass());
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("hello,server".getBytes());
        socket.shutdownOutput();
        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024];
        int readLin=0;
        while ((readLin=inputStream.read(buf))!=-1)
        {
            System.out.println(new String(buf,0,readLin));
        }
        outputStream.close();
        socket.close();
        System.out.println("socket退出");
    }
}
